require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#refuseRefund",
    data:{
        name:"",
        type:"",
        loginUid:"",
        orderNumber:"",
        refundReason:"",  //拒接说明
        imgSrc:[],
        number:1,
        complaintReason:"",  //投诉原因
        complaintDesc:"",  //投诉说明
        buyerProofDesc:"", //买家举证说明
        sellerProofDesc:""  //商家举证说明
        // afterInfo:{},
        // data:"",
        // noticeList:{},//列表
        // noticeList1:[],
        // noticeList2:[]
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.type=this.searchObject&&this.searchObject.type;
        this.loginUid=this.searchObject&&this.searchObject.uid;
        this.orderNumber=this.searchObject&&this.searchObject.orderNumber;
        if(this.type==1){   //拒绝退款
            this.name="拒绝退款";
        }else if(this.type==2){  //买家投诉
            this.name="投诉";
        }else if(this.type==3){  //买家举证
            this.name="举证";
        }else if(this.type==4){  //卖家举证
            this.name="举证";
        }else if(this.type==5){  //卖家举证
            this.name="拒绝退货";
        }
        //this.orderAfterSale();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //图片
        getChange:function(index){
            var that=this;
            var fileinput=document.getElementById("fileinput"+index).files[0];
            //创建新文件对象
            fileinput = new File([fileinput], new Date().getTime()+".png",{type:"image/jpeg"});
            that.imgSrc.splice(index,1,fileinput);
            console.log(that.imgSrc)
            lrz(fileinput, function (results) {
                // 你需要的数据都在这里，可以以字符串的形式传送base64给服务端转存为图片。
                // that.results=results;
                console.log(results)
                if(that.imgSrc.length==that.number){
                    that.number++;
                }
                document.getElementById("coverImg"+index).src=results.base64;
            });
        },
        //同意退款
        getSubmin:function(){
            console.log("111111111")
            var that=this,data,url;
            if(that.imgSrc.length>0||that.type==2&&that.type==3&&that.type==4&&that.type==5){
                console.log("22222222222")
                var formData = new FormData();
                formData.append("loginUid", that.loginUid);
                formData.append("orderNumber",that.orderNumber);
                var imgSrcList=that.imgSrc;
                for(var i=0;i<imgSrcList.length;i++){
                    formData.append("imgSrc",imgSrcList[i]);
                }
                if(that.type==1){  //拒绝退款
                    if(!that.refundReason){
                        return false;
                    }
                    formData.append("refundReason",that.refundReason);
                    url=host+"/v1/sell/sellerRefuseOrder";
                }else if(that.type==2){ //投诉
                    if(!that.complaintReason){
                        return false;
                    }
                    formData.append("complaintReason",that.complaintReason);
                    formData.append("complaintDesc",that.complaintDesc);
                    url=host+"/v1/mediaShop/userOrderComplaint";
                }else if(that.type==3){ //买家举证
                    if(!that.buyerProofDesc){
                        return false;
                    }
                    formData.append("buyerProofDesc",that.buyerProofDesc);
                    url=host+"/v1/mediaShop/buyerProof";
                }else if(that.type==4){ //卖家举证
                    if(!that.sellerProofDesc){
                        return false;
                    }
                    formData.append("sellerProofDesc",that.sellerProofDesc);
                    url=host+"/v1/sell/sellerProof";
                }else if(that.type==5){ //拒绝退货
                    if(!that.refundReason){
                        return false;
                    }
                    formData.append("refundReason",that.refundReason);
                    url=host+"/v1/sell/refuseReturnGoods";
                }
                console.log(that.imgSrc);
                $.ajax({
                    url:url,
                    type:'POST',
                    data:formData,
                    dataType:'json',
                    async: false,
                    cache: false,
                    contentType: false, //不设置内容类型
                    processData: false, //不处理数据
                    traditional:true,
                    success:function(data){
                        if(data.code==0){
                            that.getBack();
                        }
                    },
                    error:function(){
                        vm.$refs.prompt.toast("提交失败！")
                    }
                });
            }else{
                console.log("dddd")
                data={
                    loginUid:that.loginUid,
                    orderNumber:that.orderNumber,
                    refundReason:encodeURI(that.refundReason)
                };
                console.log(data)
                this.ajax({url:"/happyi/sellerRefuseOrderNotImg",data:data,dataType:"json",method:"post"},function(b){
                    if(b.json.code==0){
                        that.getBack();
                    }else{
                        vm.$refs.prompt.toast("提交失败！");
                    }
                });
            }

        },
        getComplaint:function(){
            var that=this;
            var data = [{ "id": "0", "value": "退款未达成一致" },
                { "id": "2", "value": "退款金额未达成一致" },
                { "id": "3", "value": "退款运费未达成一致" },
                { "id": "4", "value": "假货" },
                { "id": "5", "value": "其它原因" }
            ];
            var bankSelect = new IosSelect(1,
                [data],
                {
                    container: '.provingMode',
                    itemHeight: 30,
                    itemShowCount: 3,
                    callback: function (selectOneObj) {
                        console.log(selectOneObj.value)
                        that.complaintReason=selectOneObj.value;
                        // that.sellerupdatecloseorder(selectOneObj.value);
                    }
                });
        }
    }
    // ,watch:{
    //     afterInfo:function(){
    //         var that=this;
    //         that.$nextTick(function(){
    //             that.data=that.getData(that.afterInfo.currentTime,that.afterInfo.limitDate);
    //             getLive();
    //         });
    //     }
    // }
});